package com.mswordutil.markdown.builder;

import java.util.List;

import com.mswordutil.markdown.Block;
import com.mswordutil.markdown.BlockType;
import com.mswordutil.markdown.MDAnalyzer;
import com.mswordutil.markdown.MDToken;
import com.mswordutil.markdown.ValuePart;

public class QuoteBuilder implements BlockBuilder{

	private String content;
	public QuoteBuilder(String content){
		this.content = content;
	}
	
	public Block bulid() {
		Block block = new Block();
		String value = content.substring(1).trim();

		int i = 0;
		if(value.trim().startsWith(MDToken.HEADLINE)){	//检查是否有标题格式
			i = value.lastIndexOf(MDToken.HEADLINE);
		}
		if(i>0){
			value = value.substring(i+1).trim();
		}
		
		List<ValuePart> list = MDAnalyzer.analyzeTextLine(value);
		if(i>0){
			for (ValuePart valuePart : list) {
				valuePart.addType(BlockType.HEADLINE);
				valuePart.setLevel(i);
			}
		}
		
		block.setType(BlockType.QUOTE);
		block.setValueParts(list);
		return block;
	}

	public boolean isRightType() {
		return false;
	}

}
